<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>实践一下--SpringBoot配置 | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="实践是检验真理的唯一标准  本篇着重介绍一下 SpringBoot配置   写在前面 首先我们得知道为什么要使用SpringBoot，其优点有哪些？ 比如说：  简化依赖【在 pom 文件中添加相关依赖即可】 简化配置【一个普通的类，只需要 @Bean 注解即可成为一个 Bean 让 Spring 去管理】（√） 简化部署【Spring Boot 内嵌了 tomcat，我们只需要将项目打成 ja">
<meta property="og:type" content="article">
<meta property="og:title" content="实践一下--SpringBoot配置">
<meta property="og:url" content="https://curry3035.gitee.io/posts/63189/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="实践是检验真理的唯一标准  本篇着重介绍一下 SpringBoot配置   写在前面 首先我们得知道为什么要使用SpringBoot，其优点有哪些？ 比如说：  简化依赖【在 pom 文件中添加相关依赖即可】 简化配置【一个普通的类，只需要 @Bean 注解即可成为一个 Bean 让 Spring 去管理】（√） 简化部署【Spring Boot 内嵌了 tomcat，我们只需要将项目打成 ja">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2021-08-06T13:58:58.000Z">
<meta property="article:modified_time" content="2022-05-26T18:14:40.573Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="SpringBoot">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/63189/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '实践一下--SpringBoot配置',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-27 02:14:40'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">实践一下--SpringBoot配置</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-06T13:58:58.000Z" title="发表于 2021-08-06 21:58:58">2021-08-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-26T18:14:40.573Z" title="更新于 2022-05-27 02:14:40">2022-05-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AE%9E%E8%B7%B5%E7%AF%87/">实践篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="实践一下--SpringBoot配置"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>实践是检验真理的唯一标准</p>
</blockquote>
<p><strong>本篇着重介绍一下 SpringBoot配置</strong></p>
<hr>
<p><img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-08-07_19-33-18.png"></p>
<p><strong>写在前面</strong></p>
<p><font color=#008000>首先我们得知道为什么要使用SpringBoot，其优点有哪些？</font></p>
<p>比如说：</p>
<ol>
<li>简化依赖【在 pom 文件中添加相关依赖即可】</li>
<li><font color=#008000>简化配置【一个普通的类，只需要 @Bean 注解即可成为一个 Bean 让 Spring 去管理】（√）</font></li>
<li>简化部署【Spring Boot 内嵌了 tomcat，我们只需要将项目打成 jar 包】</li>
<li>简化监控【可以引入 spring-boot-start-actuator 依赖，直接使用 REST 方式来获取进程的运行期性能参数】</li>
</ol>
<span id="more"></span>



<h3 id="SpringBoot-默认配置文件"><a href="#SpringBoot-默认配置文件" class="headerlink" title="SpringBoot 默认配置文件"></a>SpringBoot 默认配置文件</h3><ul>
<li>SpringBoot使用默认的全局的配置文件：<code>application.properties</code>/<code>application.yml</code></li>
<li>配置文件名固定是是<code>application</code></li>
</ul>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line">application.properties</span><br><span class="line">	语法结构: key=value</span><br><span class="line"></span><br><span class="line">application.yml</span><br><span class="line">	语法结构: key：空格 value</span><br></pre></td></tr></table></figure>

<blockquote>
<p>个人更加的偏向于使用 yml 的形式，注意 key 后面的<font color=#008000>空格</font></p>
</blockquote>
<br/>

<h3 id="SpringBoot-配置文件的位置"><a href="#SpringBoot-配置文件的位置" class="headerlink" title="SpringBoot 配置文件的位置"></a>SpringBoot 配置文件的位置</h3><p>springboot启动会扫描以下位置的<code>application.properties</code>/<code>application.yml</code>文件作为其默认配置文件：</p>
<ul>
<li>优先级1：项目路径下的 config 文件夹配置文件</li>
<li>优先级2：项目路径下配置文件</li>
<li>优先级3：资源路径下的 config 文件夹配置文件</li>
<li><font color=#008000>优先级4：资源路径下配置文件（√）</font></li>
</ul>
<p><strong>注意</strong></p>
<ul>
<li>优先级由高到底，高优先级的配置会覆盖低优先级的配置；</li>
<li>当两个配置文件同时存在的时候，相同的配置会优先加载<code>properties</code>配置文件，多余的配置的会互补配置；</li>
</ul>
<br/>



<h3 id="SpringBoot-多环境切换"><a href="#SpringBoot-多环境切换" class="headerlink" title="SpringBoot 多环境切换"></a>SpringBoot 多环境切换</h3><p>实际开发中，我们针对不同的应用场景，可能有不同的环境，不同的配置文件</p>
<p><code>profile</code>就是Spring对不同环境提供不同配置功能的支持，可以通过激活不同的环境版本，实现快速切换环境</p>
<p>涉及两种实现方式：</p>
<h4 id="方式一：多配置文件"><a href="#方式一：多配置文件" class="headerlink" title="方式一：多配置文件"></a>方式一：多配置文件</h4><p>我们再编写配置文件时，文件名可以是<code>application-&#123;profile&#125;.properties/yml</code>，用来指定多个不同的环境版本；</p>
<p><code>application.yml</code> 【代表主环境】</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"># /src/main/resources/application.yml</span><br><span class="line"># 默认使用配置</span><br><span class="line">spring:</span><br><span class="line">  profiles:</span><br><span class="line">    active: dev</span><br></pre></td></tr></table></figure>

<p><code>application-dev.yml</code> 【代表开发环境配置】</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"># /src/main/resources/application-dev.yml</span><br><span class="line">server:</span><br><span class="line">  #  端口号</span><br><span class="line">  port: 8001</span><br></pre></td></tr></table></figure>



<p><code>application-test.yml</code> 【代表测试环境配置】</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"># /src/main/resources/application-test.yml</span><br><span class="line">server:</span><br><span class="line">  #  端口号</span><br><span class="line">  port: 8002</span><br></pre></td></tr></table></figure>



<p>如果未加指定，它默认使用<code>application.yml</code>主配置文件；</p>
<h4 id="方式二：一个配置文件【yaml的多文档块，不建议】"><a href="#方式二：一个配置文件【yaml的多文档块，不建议】" class="headerlink" title="方式二：一个配置文件【yaml的多文档块，不建议】"></a>方式二：一个配置文件【yaml的多文档块，不建议】</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line">server:  </span><br><span class="line">	port: 8080</span><br><span class="line">#选择要激活那个环境块</span><br><span class="line">spring:  </span><br><span class="line">	profiles:    </span><br><span class="line">		active: prod</span><br><span class="line">		</span><br><span class="line">---</span><br><span class="line">server:  </span><br><span class="line">	port: 8081</span><br><span class="line">spring:  </span><br><span class="line">	profiles: dev #配置环境名称dev</span><br><span class="line"></span><br><span class="line">---</span><br><span class="line">server:  </span><br><span class="line">	port: 8082</span><br><span class="line">spring:  </span><br><span class="line">	profiles: prod  #配置环境名称prod</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<br/>



<h3 id="SpringBoot-加载指定的配置文件"><a href="#SpringBoot-加载指定的配置文件" class="headerlink" title="SpringBoot 加载指定的配置文件"></a>SpringBoot 加载指定的配置文件</h3><p>通过<code>@configurationProperties</code>注解默认从全局配置文件中获取值</p>
<ul>
<li>此时配置文件名必须为<code>application</code>才能被spring认出</li>
<li>其实我们可以通过<code>@PropertySource</code>指定加载的配置文件，可以自定义文件名</li>
</ul>
<br/>



<h3 id="SpringBoot-配置类"><a href="#SpringBoot-配置类" class="headerlink" title="SpringBoot 配置类"></a>SpringBoot 配置类</h3><h4 id="注解"><a href="#注解" class="headerlink" title="注解"></a>注解</h4><p>Spring Boot 推荐使用 java 配置完全代替 XML 配置，java 配置是通过 @Configration 和 @Bean 注解实现的。二者作用如下：</p>
<ul>
<li>@Configration 注解：声明当前类是一个配置类，相当于 Spring 中的一个 XML 文件</li>
<li>@ComponentScan：作用就是根据定义的扫描路径，把符合扫描规则的类装配到spring容器中</li>
<li>@Bean 注解：作用在方法上，声明当前方法的返回值是一个 Bean</li>
</ul>
<p>@Bean 和 @Autowired 做了两件完全不同的事情：</p>
<ol>
<li>@Bean 告诉 Spring：“这是这个类的一个实例，请保留它，并在我请求时将它还给我”。</li>
<li>@Autowired 说：“请给我一个这个类的实例，例如，一个我之前用@Bean注释创建的实例”。</li>
</ol>
<h4 id="常用注解"><a href="#常用注解" class="headerlink" title="常用注解"></a>常用注解</h4><ol>
<li>@ConditionalOnBean：当容器里有指定Bean的条件下</li>
<li>@ConditionalOnMissingBean：当容器里没有指定 Bean 的情况下</li>
<li>@ConditionalOnMissingClass：当容器里没有指定类的情况下、</li>
<li>@ConditionalOnProperty：指定的属性是否有指定的值</li>
<li>@EnableConfigurationProperties的作用: 使 @ConfigurationProperties 注解的类生效。</li>
<li>@Scope(“prototype”) 表示每次获得 bean 都会生成一个新的对象【多例】</li>
<li>@AutoConfigureAfter 在加载配置的类之后再加载当前类</li>
</ol>
<h4 id="自定义"><a href="#自定义" class="headerlink" title="自定义"></a>自定义</h4><p><strong>涉及注解：</strong></p>
<ul>
<li>@EnableConfigurationProperties()【启用配置属性，指定配置类的路径或者具体类】</li>
<li>@ConfigurationProperties()【配置属性，去寻找配置文件】</li>
<li>@Configuration()【配置，声明这是一个配置类】</li>
<li>@Component()【组件，声明这是一个组件】</li>
<li>@Data()【lombok插件，生成 get 、set】</li>
</ul>
<p><strong>一、引入 SpringBoot properties 内容处理器依赖</strong></p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-configuration-processor<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>二、编写配置类</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;mall.thread&quot;)</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ThreadPoolConfigProperties</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> Integer coreSize;</span><br><span class="line">    <span class="keyword">private</span> Integer maxSize;</span><br><span class="line">    <span class="keyword">private</span> Integer keepAliveTime;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>三、properties 文件中可以联想到</strong></p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line">#配置线程池</span><br><span class="line">mall.thread.coreSize=20</span><br><span class="line">mall.thread.maxSize=200</span><br><span class="line">mall.thread.keepAliveTime=10</span><br></pre></td></tr></table></figure>

<p><strong>四、在类中使用</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@EnableConfigurationProperties(ThreadPoolConfigProperties.class)</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyThreadConfig</span> &#123;</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> ThreadPoolExecutor <span class="title function_">threadPoolExecutor</span><span class="params">(ThreadPoolConfigProperties pool)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">ThreadPoolExecutor</span>(</span><br><span class="line">                pool.getCoreSize(),</span><br><span class="line">                pool.getMaxSize(),</span><br><span class="line">                pool.getKeepAliveTime(),</span><br><span class="line">                TimeUnit.SECONDS,</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">LinkedBlockingDeque</span>&lt;&gt;(<span class="number">100000</span>),</span><br><span class="line">                Executors.defaultThreadFactory(),</span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">ThreadPoolExecutor</span>.AbortPolicy()</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/63189/">https://curry3035.gitee.io/posts/63189/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/SpringBoot/">SpringBoot</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/8859/" title="实践一下--Log日志"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">实践一下--Log日志</div></div></a></div><div class="next-post pull-right"><a href="/posts/41767/" title="每日一面--MySQL 索引"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">每日一面--MySQL 索引</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/39089/" title="实践一下--SpringBoot多模块项目"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-20</div><div class="title">实践一下--SpringBoot多模块项目</div></div></a></div><div><a href="/posts/65011/" title="每日一面--SpringBoot启动原理"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-27</div><div class="title">每日一面--SpringBoot启动原理</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBoot-%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.</span> <span class="toc-text">SpringBoot 默认配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBoot-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E4%BD%8D%E7%BD%AE"><span class="toc-number">2.</span> <span class="toc-text">SpringBoot 配置文件的位置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBoot-%E5%A4%9A%E7%8E%AF%E5%A2%83%E5%88%87%E6%8D%A2"><span class="toc-number">3.</span> <span class="toc-text">SpringBoot 多环境切换</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E5%BC%8F%E4%B8%80%EF%BC%9A%E5%A4%9A%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">3.1.</span> <span class="toc-text">方式一：多配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%96%B9%E5%BC%8F%E4%BA%8C%EF%BC%9A%E4%B8%80%E4%B8%AA%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E3%80%90yaml%E7%9A%84%E5%A4%9A%E6%96%87%E6%A1%A3%E5%9D%97%EF%BC%8C%E4%B8%8D%E5%BB%BA%E8%AE%AE%E3%80%91"><span class="toc-number">3.2.</span> <span class="toc-text">方式二：一个配置文件【yaml的多文档块，不建议】</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBoot-%E5%8A%A0%E8%BD%BD%E6%8C%87%E5%AE%9A%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">4.</span> <span class="toc-text">SpringBoot 加载指定的配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SpringBoot-%E9%85%8D%E7%BD%AE%E7%B1%BB"><span class="toc-number">5.</span> <span class="toc-text">SpringBoot 配置类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B3%A8%E8%A7%A3"><span class="toc-number">5.1.</span> <span class="toc-text">注解</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3"><span class="toc-number">5.2.</span> <span class="toc-text">常用注解</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89"><span class="toc-number">5.3.</span> <span class="toc-text">自定义</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>